/**
 * 
 */
package com.util;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
 *
 *@类名称：EncryptPropertyPlaceholderConfigurer.java
 *@类描述：
 *@创建人：zhongy
 *@创建时间：2017年4月19日-下午6:54:58
 *@修改备注:
 *@version 
 */
public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer  
{  
    private String[] encryptPropNames = {"username", "password","jdbc.url"};  
	private static final String DEFAULTKEY = "903abbd7a842060b0f50fb681d9507e6"; 
    @Override  
    protected String convertProperty(String propertyName, String propertyValue)  
    {  
        //如果在加密属性名单中发现该属性  
        if (isEncryptProp(propertyName))  
        {  
            String decryptValue="";
			try {
				decryptValue = AESUtils.decrypt(propertyValue, DEFAULTKEY);
				
	           
			} catch (Exception e) {
				
				return propertyValue;
			}  
			 return decryptValue;  
        }else {  
            return propertyValue;  
        }  
          
    }  
      
    private boolean isEncryptProp(String propertyName)  
    {  
        for (String encryptName : encryptPropNames)  
        {  
            if (encryptName.equals(propertyName))  
            {  
                return true;  
            }  
        }  
        return false;  
    }  
}  